// token 中间件
const { sendErr } = require("./reqSendResult");
const jwt = require("./jwt");
const writeRoutes = ['/api/login', '/api/login/register']
// 解析token
module.exports = (req, res, next) => {
	// 白名单验证
  if (writeRoutes.includes(req.path)) {
    next();
    return;
  }
	// 验证token
  const result = jwt.verify(req)
  if(result){
    next();
  }else{
    res.status(401).send(sendErr('token已失效重新登录', 401))
  }
};
